<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:content identifier="information" ignore="true" />
<atleap:messages />

<c:set var="maxTotal" value="${maxTotal}" />
<c:set var="maxUnique" value="${maxUnique}" />
<c:set var="maxBarWidth" value="100" />
<c:set var="barHeight" value="10" />

<table border="0" cellpadding="0" cellspacing="0" class="totalsChart">
    <tr>
        <th width="30">
            <atleap:message key="core.statistics.totals.year" />
        </th>
        <th width="30">
            <atleap:message key="core.statistics.totals.month" />
        </th>
        <th></th>
        <th width="30">
            <atleap:message key="core.statistics.totals.number" />
        </th>
    </tr>
    <atleap:iterator items="${years}" var="yearDescr">
        <c:set var="year" value="${yearDescr[0]}" />
        <c:set var="months" value="${yearDescr[1]}" />
        <bean:size id="numberOfMonths" collection="${months}" />
        <atleap:iterator items="${months}" var="monthDescr" statusVar="status">
            <c:set var="month" value="${monthDescr[0]}" />
            <c:set var="total" value="${monthDescr[1]}" />
            <c:set var="unique" value="${monthDescr[2]}" />
            <c:set var="totalFraction" value="${total / maxTotal}" />
            <c:set var="uniqueFraction" value="${unique / maxUnique}" />
            <fmt:formatNumber value="${totalFraction * maxBarWidth}" maxFractionDigits="0" groupingUsed="false" var="totalBarWidth" />
            <fmt:formatNumber value="${uniqueFraction * maxBarWidth}" maxFractionDigits="0" groupingUsed="false" var="uniqueBarWidth" />
            <tr>
                <c:if test="${status.first}">
                    <td rowspan="${numberOfMonths}" align="center">${year}</td>
                </c:if>
                <td align="center">
                    <atleap:formatDate value="${month}/01/2000" pattern="MMMMM" />
                </td>
                <td>
                    <table border="0" cellpadding="0" cellspacing="0" class="twoRowTable">
                        <tr>
                            <td class="twoRowTableCell">
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/statistics/color1_pixel.gif" />" width="${totalBarWidth}%" height="${barHeight}" />
                            </td>
                        </tr>
                        <tr>
                            <td class="twoRowTableCell">
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/statistics/color2_pixel.gif" />" width="${uniqueBarWidth}%" height="${barHeight}" />
                            </td>
                        </tr>
                    </table>
                </td>
                <td>
                    <table border="0" cellpadding="0" cellspacing="0" class="twoRowTable">
                        <tr>
                            <td align="center" class="twoRowTableCell">
                                ${total}
                            </td>
                        </tr>
                        <tr>
                            <td align="center" class="twoRowTableCell">
                                ${unique}
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </atleap:iterator>
    </atleap:iterator>
    <bean:size id="numberOfYears" collection="${years}" />
    <c:if test="${numberOfYears == 0}">
        <tr>
            <td class="tfoot" colspan="4" align="center">
                <em><atleap:message key="core.commons.nothingToShow"/></em>
            </td>
        </tr>
    </c:if>
</table>

<h3><atleap:message key="core.statistics.legend" /></h3>
<table border="0" cellpadding="0" cellspacing="0" class="totalsChartLegend">
    <tr>
        <th>
            <atleap:message key="core.statistics.totals.total" />
        </th>
        <td>
            <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/statistics/color1_pixel.gif" />" width="${maxBarWidth}" height="${barHeight}" />
        </td>
    </tr>
    <tr>
        <th>
            <atleap:message key="core.statistics.totals.unique" />
        </th>
        <td>
            <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/statistics/color2_pixel.gif" />" width="${maxBarWidth}" height="${barHeight}" />
        </td>
    </tr>
</table>

<atleap:form action="core/statistics/showPanel" method="GET" validateOnSubmit="false">
    <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.back" /></atleap:submit>
</atleap:form>
